#!/bin/bash

set -x

dir="/mnt/yanyi/ceph/build/"
cd ${dir}

hostname=`hostname`

osd_name=`ls /data |grep osd`
echo $osd_name
array=(${osd_name//./ })
osd_id=${array[${#array[@]}-1]}
echo $osd_id
# generate an osd id。
bin/ceph osd create
sleep 1

# general keyring of osd
bin/ceph-osd -i ${osd_id} --mkfs --mkkey --no-mon-config
sleep 1

# add keyring of osd into ceph auth
bin/ceph auth add osd.${osd_id} osd 'allow *' mon 'allow profile osd' -i /data/osd.${osd_id}/keyring
sleep 1

# create a host in crushmap
bin/ceph osd crush add-bucket ${hostname} host
sleep 1

# add the host into root of crushmap
bin/ceph osd crush move ${hostname} root=default
sleep 1

# add osd.0 into host ins01
bin/ceph osd crush add osd.${osd_id} 1.0 host=${hostname}
sleep 1

# start osd service
bin/ceph-osd -i ${osd_id}
